#!/bin/sh
#
# 部署笔记后端
#
app_dir="/opt/mojito/"
app_name="mojito-note-back"

# 1 代表首次构建
if [[ $1 == "1" ]]; then
  cd $root_dir
  git clone git@gitee.com:itstrongs/mojito-parent.git
  git clone git@gitee.com:itstrongs/mojito-common.git
  git clone git@gitee.com:itstrongs/mojito-note.git

  cd ${app_dir}mojito-parent
  mvn clean install

  cd ${app_dir}mojito-common
  mvn clean install
fi

# 打包
cd ${app_dir}${app_name}
git pull
mvn clean install -DskipTests=true

# 容器化
if docker ps -a | grep -q ${app_name}; then
  docker stop ${app_name}
  docker rm ${app_name}
  docker rmi ${app_name}
fi

docker build -t ${app_name} .
docker run -v ${app_dir}logs/${app_name}:/root/logs/${app_name} --name ${app_name} -d -p 18086:18086 ${app_name}

echo "------------ 部署完成 ------------"
